using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CocaCola_Inventory_System.Forms
{
    public partial class insertDepersionation : Form
    {
        public System.Data.Odbc.OdbcConnection con;
        public insertDepersionation()
        {
            InitializeComponent();
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btn_insert_Click(object sender, EventArgs e)
        {
            try
            {
                int val = 0;
                if (txt_name.Text.Length > 0 && int.TryParse(txt_val.Text, out val) && txt_description.Text.Length > 0)
                    if (Data_Access.depersonationDB.InsertDepresionation(this.con, txt_name.Text, val, txt_description.Text))
                    {
                        MessageBox.Show("Entry successfully added to the database", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Error adding entry to the database", "Success", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                        throw new Exception("category insert failed");
                    }
                else
                    MessageBox.Show("You must supply a valid name and value.", "Insert Depresionation", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
            catch (Exception ex)
            {
                Data_Access.Common.ReportError(ex);
            }
        }
    }
}